close all; clear; clc;

m = 1; M = 1; l = 1; g = 9.80665;

A = [0, 1, 0, 0;
    0, 0, m * g / M, 0;
    0,0, 0, 1;
    0, 0, (m + M) * g / (M * l), 0];
B = [0; 1 / M; 0; 1 / (M * l)];
C = [1, 0, 0, 0;
    0, 1, 0, 0;
    0, 0, 1, 0;
    0, 0, 0, 1];
D = [0; 0; 0; 0];

Q = [1, 0, 0, 0;
    0, 1, 0, 0;
    0, 0, 1, 0;
    0, 0, 0, 1];
R = [1];

K = lqr(A, B, Q, R);

simOut = sim('sim_dyn');